/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2011 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _VIEWPORTOPENGLES_H_
#define _VIEWPORTOPENGLES_H_

#include "RenderMethodOpenGLES.h"

#include "YGViewport.h"

namespace YoghurtGum
{

	class ViewportOpenGLES : public Viewport
	{
	
		friend class RenderMethodOpenGLES;

	public:

		void Resize(uint32 a_Width, uint32 a_Height);

		/*
			Set the type of viewport. 
			The World refers to the entire world, which can be the same size, smaller or bigger than the viewport.
			The Screen refers to the physical dimensions of the display device.
			The View refers to the visible pixels of the World on the Screen.
			The following types are available:
			YG_VIEWPORT_NOTHING     = Do nothing when the Screen is different than the View.
			YG_VIEWPORT_SCALEX      = Stretch the width of the View until it matches the Screen width.
			YG_VIEWPORT_SCALEY      = Stretch the height of the View until it matches the Screen height.
			YG_VIEWPORT_SCALEXY     = Scale both the width and the height of the View until it matches the Screen.
			YG_VIEWPORT_VIEWPORT	= 
			YG_VIEWPORT_CENTER      = Center the View on the Screen. The View is cropped when the Screen is too small.
			YG_VIEWPORT_TOPLEFT     = Put the View on the top-left of the Screen. 
			YG_VIEWPORT_TOPRIGHT               0x000000080
			YG_VIEWPORT_BOTTOMLEFT             0x000000100
			YG_VIEWPORT_BOTTOMRIGHT            0x000000200
		*/
		void SetType(uint32 a_Type);

		/*
			Sets the horizontal and vertical boundaries. This is the space between the screen borders and the centered object.
		*/
		void SetBounds(Vec2 a_Dim);

		/*
			Get a screen position based on this Viewport. Used for drawing sprites on screen.
		*/
		Vec2 GetScreenPosition(Vec2 a_WorldPos);
		/*
			Check a world position with the view. Moves the Viewport when necessary.
		*/
		Vec2 GetCenterPosition(Vec2 a_WorldPos);

		void SetX(real32 a_X);
		void SetY(real32 a_Y);
		void SetPosition(real32 a_X, real32 a_Y);
		void Move(real32 a_SpeedX, real32 a_SpeedY);

		void SetTargetPosition(uint32 a_X, uint32 a_Y);
		void SetDimensions(uint32 a_Width, uint32 a_Height);

		/*
			Set the size of the world. When a Viewport is created it is set to the size of the screen.
		*/
		void SetWorldDimensions(uint32 a_Width, uint32 a_Height);

		bool Enable();
		bool Disable();

		void Project();

	private:
	
		ViewportOpenGLES(uint32 a_Width, uint32 a_Height, uint32 a_Type = YG_VIEWPORT_DEFAULT);
		~ViewportOpenGLES();

		int32 m_Width, m_Height;
		Vec2 m_Pos;

		uint32 m_ScissorStartX, m_ScissorStartY;
		uint32 m_ScissorEndX, m_ScissorEndY;

		GLfixed m_WorldFixedWidth, m_WorldFixedHeight;
		GLfixed m_FixedWidth, m_FixedHeight;
		GLfixed m_ZNear, m_ZFar;

		Vec2 m_Offset;

		bool m_Viewport;
	
	}; // class ViewportOpenGLES

}; // namespace YoghurtGum
	
#endif